package com.fastwire.carriere.rad.controller;

import java.util.List;
import java.util.Set;

import com.fastwire.carriere.dao.DAOException;
import com.fastwire.carriere.dao.DAOFactory;
import com.fastwire.carriere.rad.dao.RadAlarmDao;
import com.fastwire.carriere.rad.dao.RadLogDao;
import com.fastwire.carriere.rad.entity.RadAlarm;
import com.fastwire.carriere.rad.entity.RadLog;
import com.fastwire.carriere.rad.snmpadapter.TrapReceiver;

/**
 * @author Jun
 * Created on 20120501
 */
public class TrapMsgControllerImp implements TrapMsgController 
{
	RadProcessController radProcessor = new RadProcessControllerImp();
	
	@Override
    public void startTrap()
    {
    	TrapReceiver.startListen(this);
    }

	/* (non-Javadoc)
	 * @see com.fastwire.carriere.rad.controller.TrapMsgController#updateRadByIP(java.util.Set)
	 */
	@Override
	public String updateRadByIP(Set<String> ips)
	{
		try
		{
			for(String ip : ips)
			{
				radProcessor.adhocDiscovery(ip);
			}
		}
		catch (DAOException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return null;
	}

	/* (non-Javadoc)
	 * @see com.fastwire.carriere.rad.controller.TrapMsgController#updateRad(java.util.Set)
	 * /
	@ Override
	public String updateRads(List<Rad> rads) 
	{
	    RadDao radDao =  DAOFactory.getInstance().getRadDao();

        try
        {
            radDao.saveOrUpdate(rads);
        }
        catch (DAOException e) 
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        
		return null;
	}*/

	/* (non-Javadoc)
	 * @see com.fastwire.carriere.rad.controller.TrapMsgController#updateRadAlarms(java.util.ArrayList)
	 */
	@Override
	public String updateRadAlarms(List<RadAlarm> alarms)
	{
		RadAlarmDao alarmDao =  DAOFactory.getInstance().getRadAlarmDao();

		try
		{
			alarmDao.saveOrUpdate(alarms);
		}
		catch (DAOException e) 
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return null;
	}

	/* (non-Javadoc)
	 * @see com.fastwire.carriere.rad.controller.TrapMsgController#updateRadLogs(java.util.ArrayList)
	 */
	@Override
	public String updateRadLogs(List<RadLog> logs)
	{
		RadLogDao logDao = DAOFactory.getInstance().getRadLogDao();
		
		try
		{
		    logDao.saveOrUpdate(logs);
		}
		catch (Exception e)
		{
		    e.printStackTrace();
		}
		
		return null;
	}

}
